// pages/xgPreventionGuide/nucleicAcid/index.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    barMarginTop: '16',
    barHeight: '52',
    barWidth: '0',
    scrollHeight: '',
    value: [0, 0],
    cityData: [],
    citysPickerShow: false,
    curCity: {},
    list: [],
    noData: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBarHeight()
    this.setListHeight()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},

  /**
   * 设置导航栏高度
   */
  getBarHeight() {
    let systemInfo = wx.getSystemInfoSync()
    let	statusBarHeight = systemInfo.statusBarHeight
    let menu = wx.getMenuButtonBoundingClientRect()

    let	barMarginTop = menu.top
    let	barHeight = menu.height + 10
    let barWidth = systemInfo.windowWidth - (systemInfo.windowWidth - menu.right + menu.width)

    this.setData({
      barMarginTop: barMarginTop,
      barHeight: barHeight,
      barWidth: barWidth
    })
  },

  /**
   * 设置scroll-view高度
   */
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      hei = 52,
      tapHeight = Math.floor(rpx * hei * 2), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      scrollHeight
    });
  },
  scrolltolower() {},

  getData() {
    const _this = this
    const key = '8f4951d26179db3f21b00729a53b7d37'
    app._get('http://apis.juhe.cn/springTravel/hsjg', {key: key, city_id: _this.data.curCity.cityId},
        (res) => {
          if(res.result.data) {
            _this.setData({
              list: res.result.data,
              noData: false,
            })
          } else {
            _this.setData({
              list: [],
              noData: true,
            })
          }
        }, (err) => {
          // error callback
        }, (com) => {
          // complete callback
        })
  },

  showCitysPicker() {
    this.setData({
      citysPickerShow: true
    })
  },
  citysPikcerSubmit(e) {
    this.setData({
      curCity: e.detail
    })
    this.getData()
  },
  makePhoneCall(e) {
    const phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },
})